import {ObjectInformation, WindowInformation, DisplayZone} from "../event-types";

export class MeasureDisplayZone implements DisplayZone {
    color: string = 'rgba(120, 0, 0, 0.5)';
    height: number = 1021 - 100;

    isVisible(displayInformation: ObjectInformation[], window: WindowInformation): boolean {
        return !displayInformation.some(d => d.label.startsWith('Elternknoten'))  && displayInformation.some(d => d.label === 'Kennzahlen');
    }

    label: string = 'Measures';
    referenceHeight: number = 1059;
    referenceWidth: number = 1920;
    width: number = 384;
    x: number = 0;
    y: number = 100;

    copy(): DisplayZone {
        return new MeasureDisplayZone();
    }

}

export class DimensionDisplayZone implements DisplayZone {
    color: string = 'rgba(0, 120, 0, 0.5)';
    height: number = 551 - 80;

    isVisible(displayInformation: ObjectInformation[], window: WindowInformation): boolean {
        return displayInformation.some(d => d.label.startsWith('Elternknoten')) && displayInformation.some(d => d.label === 'Dimensionen');
    }

    label: string = 'Dimensions & Hierarchies';
    referenceHeight: number = 1059;
    referenceWidth: number = 1920;
    width: number = 384;
    x: number = 0;
    y: number = 80;

    copy(): DisplayZone {
        return new DimensionDisplayZone();
    }

}

export class LevelDisplayZone implements DisplayZone {
    color: string = 'rgba(0, 0, 120, 0.5)';
    height: number = 1019 - 666;

    isVisible(displayInformation: ObjectInformation[], window: WindowInformation): boolean {
        return displayInformation.some(d => d.label.startsWith('Elternknoten')) && displayInformation.some(d => d.label === 'Dimensionen');
    }

    label: string = 'Levels';
    referenceHeight: number = 1059;
    referenceWidth: number = 1920;
    width: number = 192;
    x: number = 0;
    y: number = 666;

    copy(): DisplayZone {
        return new LevelDisplayZone();
    }
}

export class MemberDisplayZone implements DisplayZone {
    color: string = 'rgba(0, 120, 120, 0.5)';
    height: number = 1019 - 666;

    isVisible(displayInformation: ObjectInformation[], window: WindowInformation): boolean {
        return displayInformation.some(d => d.label.startsWith('Elternknoten')) && displayInformation.some(d => d.label === 'Dimensionen');
    }

    label: string = 'Members';
    referenceHeight: number = 1059;
    referenceWidth: number = 1920;
    width: number = 386 - 193;
    x: number = 193;
    y: number = 666;

    copy(): DisplayZone {
        return new MemberDisplayZone();
    }
}

export class SelectionDisplayZone implements DisplayZone {
    color: string = 'rgba(120, 0, 120, 0.5)';
    height: number = 733;

    isVisible(displayInformation: ObjectInformation[], window: WindowInformation): boolean {
        const heightScale = window.height / this.referenceHeight;
        const relevantFields = displayInformation.filter(i => i.label.startsWith('Kennzahlauswahl'));
        return relevantFields.some(s => s.y * heightScale < 50);
    }

    label: string = 'Selection';
    referenceHeight: number = 1059;
    referenceWidth: number = 1920;
    width: number = 769 - 404;
    x: number = 404;
    y: number = 0;

    copy(): DisplayZone {
        return new SelectionDisplayZone();
    }
}

export class MemberSelectionDisplayZone implements DisplayZone {
    color: string = 'rgba(120, 120, 0, 0.5)';
    height: number = 1019 - 850;

    isVisible(displayInformation: ObjectInformation[], window: WindowInformation): boolean {
        const adHocNode = displayInformation.find(e => e.label === 'Adhoc-Knoten erstellen');
        return displayInformation.some(i => i.label.startsWith('Löschen')) && (adHocNode?.y ?? 0) > 20;
    }

    label: string = 'Member Selection';
    referenceHeight: number = 1059;
    referenceWidth: number = 1920;
    width: number = 1920 - 600;
    x: number = 600;
    y: number = 850;

    copy(): DisplayZone {
        return new MemberSelectionDisplayZone();
    }
}

export class VisualisationSelectionDisplayZone implements DisplayZone {
    color: string = 'rgba(0, 120, 120, 0.5)';
    height: number = 120 - 31;

    isVisible(displayInformation: ObjectInformation[], window: WindowInformation): boolean {
        const heightScale = window.height / this.referenceHeight;
        const relevantFields = displayInformation.filter(i => i.label.startsWith('VISUALISIERUNGEN'));
        return relevantFields.some(s => s.y * heightScale < 35);
    }

    label: string = 'Visualisation Selection';
    referenceHeight: number = 1059;
    referenceWidth: number = 1920;
    width: number = 1910 - 1640;
    x: number = 1640;
    y: number = 31;

    copy(): DisplayZone {
        return new VisualisationSelectionDisplayZone();
    }
}

export class VisualisationDisplayZone implements DisplayZone {
    color: string = 'rgba(120, 120, 120, 0.5)';
    height: number = 802;

    isVisible(displayInformation: ObjectInformation[], window: WindowInformation): boolean {
        const heightScale = window.height / this.referenceHeight;
        const relevantFields = displayInformation.filter(i => i.label.startsWith('VISUALISIERUNGEN'));
        return relevantFields.some(s => s.y * heightScale < 35);
    }

    label: string = 'Visualisation';
    referenceHeight: number = 1059;
    referenceWidth: number = 1920;
    width: number = 1630 - 768;
    x: number = 768;
    y: number = 0;

    copy(): DisplayZone {
        return new VisualisationDisplayZone();
    }
}

export const displayZones: DisplayZone[] = [
    new MeasureDisplayZone(),
    new DimensionDisplayZone(),
    new LevelDisplayZone(),
    new MemberDisplayZone(),
    new SelectionDisplayZone(),
    new MemberSelectionDisplayZone(),
    new VisualisationSelectionDisplayZone(),
    new VisualisationDisplayZone()
];